package org.dromara.app.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.satoken.utils.LoginHelper;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.bean.domain.vo.HisQuestionnaireAnswerVo;
import org.dromara.bean.domain.bo.HisQuestionnaireAnswerBo;
import org.dromara.bean.service.IHisQuestionnaireAnswerService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 答题记录
 *
 * @author Lion Li
 * @date 2024-12-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/questionnaireAnswer")
public class AHisQuestionnaireAnswerController extends BaseController {

    private final IHisQuestionnaireAnswerService hisQuestionnaireAnswerService;


    /**
     * 查询答题记录列表
     */
    @GetMapping("/list")
    public TableDataInfo<HisQuestionnaireAnswerVo> list(HisQuestionnaireAnswerBo bo, PageQuery pageQuery) {
        return hisQuestionnaireAnswerService.queryPageList(bo, pageQuery);
    }



    /**
     * 获取答题记录详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<HisQuestionnaireAnswerVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(hisQuestionnaireAnswerService.queryById(id));
    }

    /**
     * 新增答题记录
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HisQuestionnaireAnswerBo bo) {
        bo.setMemberId(LoginHelper.getUserId());
        return toAjax(hisQuestionnaireAnswerService.insertByBo(bo));
    }


}
